#include <stdio.h>
#include <math.h>
#include "cv.h"
#include "highgui.h"
     
void drawArrow2(double angle, double speed)
{

	IplImage *img = cvCreateImage(cvSize(400, 300), IPL_DEPTH_8U, 3);

	// determination de la longueur selon la vitesse
	int length = (int)floor(speed*5);

	// origine de l'image (centre)
	CvPoint* origine = new CvPoint();
	origine->x = 200;
	origine->y = 150;


	// coordonnees cartesiennes de l'extremite deduites de ses coordonnees polaires (vitesse traduite en distance et angle en radians)
	int x = (int)floor(length*cos(angle));
	int y = (int)floor(length*sin(angle));

	// Adaptation des coordonnees au referentiel de l'image
	// Premiere extremite de la droite
	CvPoint* e1 = new CvPoint();
	e1->x = 200-y;
	e1->y = 150-x;
	// Seconde extremite de la droite
	//~ cvPoint e2 = cvPoint(200+y, 150+x);
	CvPoint* e2 = new CvPoint();
	e2->x = 200+y;
	e2->y = 150+x;

	/* draw the main line */
	cvLine(img,                  /* the dest image */
        *origine,          	     /* start point */
        *e1,           		     /* end point */
        cvScalar(0, 0, 255, 0),      /* the color; red */
        5, 8, 0);                    /* thickness, line type, shift */

	/* draw the opposite line */
	cvLine(img,                  /* the dest image */
        *origine,          	     /* start point */
        *e2,           		     /* end point */
        cvScalar(0, 255, 0, 0),      /* the color; green */
        5, 8, 0);                    /* thickness, line type, shift */

	/* display the image */
        cvNamedWindow("img", CV_WINDOW_AUTOSIZE);
        cvShowImage("img", img);
        cvWaitKey(0);
        cvDestroyWindow("img");
        cvReleaseImage(&img);
 
}

void emptyImage(){
	IplImage *img = cvCreateImage(cvSize(400, 300), IPL_DEPTH_8U, 3);
	/* display the image */
	cvNamedWindow("img", CV_WINDOW_AUTOSIZE);
	cvShowImage("img", img);
	cvWaitKey(0);
	cvDestroyWindow("img");
	cvReleaseImage(&img);
}

int main(int argc, char** argv){
	
	//drawArrow2(0, 10);
	//emptyImage();
	//drawArrow2(1.57, 10);
	//emptyImage();
	//drawArrow2(3.14, 10);
	//emptyImage();
	//drawArrow2(4.72, 10);
	//emptyImage();
	//drawArrow2(0, 10);
	drawArrow2(5, 10);
	
}
